﻿@*@model Cxuu.Models.ViewArticleCate *@
@{
    ViewData["Title"] = "视频列表";
}
<div class="content-top-nav">
    <h3 style="color:#444"><i class="layui-icon layui-icon-home"></i>@ViewData["Title"] </h3>
    <hr>
</div>
<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" action="" lay-filter="FormSearch" enctype="multipart/form-data">
                    <div class="layui-card-body ">
                        <div class="layui-form">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="keyword" id="keyword" placeholder="按标题搜索" class="layui-input" style="width:320px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select name="searchcid" id="searchcid" lay-verify="">
                                    <option value="0">所有栏目</option>
                                    @foreach (var item in ViewBag.catelist)
                                    {
                                        <option value="@item.Id">@item.Title</option>
                                    }
                                </select>
                            </div>
                            <div class="layui-inline layui-show-xs-block" style="width:80px;">
                                <select id="stat" name="stat" lay-verify="required">
                                    <option value="">全部</option>
                                    <option value="1">已审</option>
                                    <option value="0">草稿</option>
                                </select>
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" data-type="reload" id="searchBtn"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <script type="text/html" id="toolbarAE">
                <div class="layui-btn-container">
                    @if (CheckExt.AuthView(ViewBag.sr, "extvideo_addoredit"))
                    {
                        <button class="layui-btn layui-btn-sm data-add-btn">新增</button>
                    }
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="cateUrlTpl">
                <a href="/Home/Video/List/{{d.cid}}" target="_blank">{{d.cateName}}</a>
            </script>
            <script type="text/html" id="contentUserTpl">
                {{d.nickname}}
            </script>
            <script type="text/html" id="contentGroupTpl">
                {{d.groupname}}
            </script>
            <script type="text/html" id="contentUrlTpl">
                <a href="/Home/Video/Info/{{d.id}}" target="_blank">{{d.title}}</a>
            </script>
            @if (CheckExt.AuthView(ViewBag.sr, "extvideo_status"))
            {
                <script type="text/html" id="status">
                    <input type="checkbox" name="Status" id="{{d.id}}" value="{{d.Status}}" lay-skin="switch" lay-text="审|审" lay-filter="switchStatus" {{ d.status == 1 ? "checked" : "" }}>
                </script>
            }
            else
            {
                <script type="text/html" id="status">
                    {{#if (d.status == 1){ }}
                    <span class='layui-badge layui-bg-green'>已审</span>
                    {{#  }else{ }}
                    <span class='layui-badge layui-bg-red'>未审</span>
                    {{# } }}
                </script>
            }
            @if (CheckExt.AuthView(ViewBag.sr, "extvideo_att"))
            {
                <script type="text/html" id="switch">
                    <input type="checkbox" name="AttA" id="{{d.id}}" value="{{d.AttA}}" lay-skin="switch" lay-text="头|头" lay-filter="switchStatus" {{ d.attA == 1 ? "checked" : "" }}>
                    <input type="checkbox" name="AttB" id="{{d.id}}" value="{{d.AttB}}" lay-skin="switch" lay-text="小|小" lay-filter="switchStatus" {{ d.attB == 1 ? "checked" : "" }}>
                    <input type="checkbox" name="AttC" id="{{d.id}}" value="{{d.AttC}}" lay-skin="switch" lay-text="轮|轮" lay-filter="switchStatus" {{ d.attC == 1 ? "checked" : "" }}>
                </script>
            }
            else
            {
                <script type="text/html" id="switch">
                    {{#  if(d.imgbl == 1){ }}
                    <i class='layui-icon layui-icon-picture' style='color:#1E9FFF'></i>
                    {{#  } }}
                    {{#  if(d.attA == 1){ }}
                    <span class='layui-badge layui-bg-blue'>头条</span>
                    {{#  } }}
                    {{#  if(d.attB == 1){ }}
                    <span class='layui-badge layui-bg-blue'>小头条</span>
                    {{#  } }}
                    {{#  if(d.attC == 1){ }}
                    <span class='layui-badge layui-bg-blue'>轮换</span>
                    {{#  } }}
                </script>
            }
            <script type="text/html" id="currentTableBar">
                @if (CheckExt.AuthView(ViewBag.sr, "extvideo_addoredit"))
                {
                    <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                }
                @if (CheckExt.AuthView(ViewBag.sr, "extvideo_delete"))
                {
                    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
                }
            </script>

        </div>
    </div>
</div>
<script>
    layui.use(['table', 'layer', 'jquery', 'form'], function () {
        var table = layui.table,$ = layui.jquery,layer = layui.layer,form = layui.form;

        form.render();

        form.val('FormSearch', {
            searchcid: @ViewBag.cid,
        });

        table.render({
            elem: '#currentTableId',
            //url: '/res/admin/api/table.json',
            url: '/Admin/Extvideo/Index?cid=@ViewBag.cid&json=1',
            toolbar: '#toolbarAE',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            cols: [[
                //{type: "checkbox", width: 50, fixed: "left"},
                { field: 'id', width: 80, title: 'ID', sort: true },
                { field: 'cateName', width: 120, title: '栏目', templet: '#cateUrlTpl' },
                { field: 'title', title: '标题', templet: '#contentUrlTpl' },
                { field: 'nickname', width: 100, title: '发布人', templet: '#contentUserTpl' },
                { field: 'groupname', width: 100, title: '发布角色', templet: '#contentGroupTpl' },
                { field: 'examine', width: 100, title: '作者'},
                { field: 'time', width: 200, title: '发布时间', sort: true },
                { field: 'status', width: 80, title: '状态', templet: '#status', unresize: true },
                { field: 'imgbl', width: 200, title: '属性', templet: '#switch', unresize: true },
                { title: '操作', width: 160, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            id: 'tableReload',
            page: true
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/Extvideo/AddOrEdit?cid=@ViewBag.cid');
            return false;
        });
        // 监听删除操作
        $(".data-delete-btn").on("click", function () {
            var checkStatus = table.checkStatus('currentTableId'),data = checkStatus.data;
            layer.alert(JSON.stringify(data));
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        //监听状态操作
        form.on('switch(switchStatus)', function (obj) {
            $.post('/Admin/Extvideo/SwitchStatus',
                { id: this.id, status: obj.elem.checked ? 1 : 0, att: obj.elem.name },
                function (res) {
                    layer.tips(res.msg, obj.othis, {
                        tips: 1
                    });
                });
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                loadMain('/Admin/Extvideo/AddOrEdit?&id=' + data.id);
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('删除确认？', function (index) {
                    $.post('/Admin/Extvideo/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            }
        });

        //搜索重载表格
        $('#searchBtn').on('click', function () {
            table.reload('tableReload', {
                method: 'get',
                where: {
                    keyword: $('#keyword').val(),
                    searchcid: $('#searchcid').val(),
                    stat: $('#stat').val(),
                },
                page: {
                    curr: 1
                },
                page: true,
            });
            return false;
        });
    });
</script>